package cn.bone.mqtt.service;

import com.alibaba.fastjson.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHandler;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.MessagingException;
import org.springframework.stereotype.Service;


/**
 * Created by MD-01 on 2017/3/14.
 */
@Service
public class ReceiveService implements MessageHandler {

    private Logger logger = LoggerFactory.getLogger("接收方");


    @ServiceActivator(inputChannel = "mqttInputChannel")
    @Override
    public void handleMessage(Message<?> message) throws MessagingException {
        String payload = (String)message.getPayload();
        MessageHeaders headers = message.getHeaders();
        logger.info("payload:"+payload);
        logger.info("headers:"+ JSON.toJSON(headers));
    }
}
